package com.taxigang.client.uibinder;


import com.allen_sauer.gwt.log.client.Log;
import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.Widget;
import com.taxigang.client.Session;
import com.taxigang.client.facebook.FacebookApi;
import com.taxigang.client.micro.TaxiGangCreator;
import com.taxigang.client.ui.map.MapView.PanelType;
import com.taxigang.shared.TaxiGangInfo;

public class CongratulationsCreate extends TaxiGangPanel  {

	private static CongratulationsCreateUiBinder uiBinder = GWT
	.create(CongratulationsCreateUiBinder.class);

	interface CongratulationsCreateUiBinder extends
	UiBinder<Widget, CongratulationsCreate> {
	}

	@UiField Button closeButton;
	@UiField Label sorryText;
	@UiField
	Label headerLabel;

	public CongratulationsCreate() {
		initWidget(uiBinder.createAndBindUi(this));
		sorryText.setText(TaxiGangCreator.taxiGangConstants.congratulationsCreate());
		closeButton.setText(TaxiGangCreator.taxiGangConstants.cont());
		headerLabel.setText(TaxiGangCreator.taxiGangConstants.congratulations());

		closeButton.addClickHandler(new ClickHandler() {


			@Override
			public void onClick(ClickEvent event) {

				taxiGangRoute.show(PanelType.MYTAXIGANGS);

			}
		});

	}

	@Override
	public void show(){
		super.show();
		TaxiGangInfo info = Session.getInstance().getCurrentMyTaxiGang();
		if (info != null){
			String link = info.getLink();

			String msgBody = TaxiGangCreator.taxiGangConstants.invitationGreeting()+"\n";;
			msgBody += TaxiGangCreator.taxiGangConstants.from()+":"+info.getStart()+"\n";
			msgBody += TaxiGangCreator.taxiGangConstants.time()+":"+info.getDepartureTime()+"\n";


			//FacebookApi.postToFeed(msgBody, link); //post to own page
			String page = info.getPage();
			if (page != null && page.trim().length() >0){
				String feed = "/"+page+"/feed";
				String accessToken = info.getPageAccessToken();
				FacebookApi.postToTaxigangPage(msgBody, link, feed, accessToken); //post to local page
			}
		} else {
			Log.warn("CongratulationsCreate: info is null");
		}

	}
}
